<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"  @submit.native.prevent @keyup.enter.native="handleQuery">
      <el-form-item label="申请人" prop="qKey">
        <el-input v-model="queryParams.qKey" placeholder="姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="部门" prop="qIds1">
        <el-cascader
          v-model="queryParams.qIds1"
          :options="deptList"
          :props="{value: 'id',children: 'children',label: 'label',expandTrigger:'hover'}"
          filterable
          clearable
          placeholder=""
          style="width: 400px;"
        ></el-cascader>
      </el-form-item>
      <el-form-item label="申请时间" prop="qTimeStartList">
        <el-date-picker
          v-model="queryParams.qTimeStartList"
          type="daterange"
          range-separator="-"
          start-placeholder="起"
          end-placeholder="止"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="姓名" align="center" prop="nickName" fixed/>
      <el-table-column label="部门" align="center" prop="deptName" width="200"/>
      <el-table-column label="申请积分" align="center" prop="score" />
      <el-table-column label="申请项目数" align="center" prop="numItem" />
      <el-table-column label="申请时间" align="center" prop="timeStart" />
      <el-table-column label="申请状态" align="center" prop="applyStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.apply_status" :value="scope.row.applyStatus"/>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"  width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['points:poiApplyExamine:poiApplyExamine']"
            @click="handlePass(scope.row)"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



    <el-dialog :title="title" v-if="open" :visible.sync="open" width="90%" top="500vh" append-to-body>
      <div style="max-height: 600px;overflow-y: auto;">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <ApplyInfo :apply-id="form.id"></ApplyInfo>
          <el-row>
            <el-col :span="10">
              <el-form-item label="申请合计分数" >
                {{form.score +'分'}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="审核" prop="pass">
                <el-radio-group v-model="form.pass" size="small">
                  <el-radio-button
                    v-for="dict in [{label:'通过',value:1},{label:'退回',value:0}]"
                    :key="dict.value"
                    :label="dict.value"
                  >{{ dict.label }}
                  </el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10">
              <el-form-item label="备注" prop="notes">
                <el-input type="textarea" v-model="form.notes"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary"  @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>

import ApplyInfo from "@/views/points/applyInfo/applyInfo";

export default {
  name : "PoiApplyExamine",
  components: {
    ApplyInfo
  },
  dicts: ['apply_status','pass'],
  data() {
    return {
      deptList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        qKey: "",
        qIds1: undefined,
        qTimeStartList: undefined,
        qStatus: undefined,
        pageNum: 1,
        pageSize: 10,
        isAsc:undefined,
        orderByColumn:undefined
      },
      dialogTableVisible:false,

      form: {
        id : undefined,
        applyIds : undefined,
        score  : undefined,
        pass : undefined,
        notes : undefined,
      },
      // 表单校验
      rules: {
        pass: [{ required: true, message: "不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    //this.getList();
    this.getDepts();
  },
  activated() {
    this.getList();
  },
  methods: {
    getDepts(){
      this.request({
        url: '/system/user/deptTree',
        method: 'get',
      }).then(response => {
        this.deptList = response.data;
      });
    },
    getList() {
      this.loading = true;
      this.request({
        url: '/points/poiApplyExamine/list',
        method: 'get',
        params: this.queryParams
      }).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.isAsc = undefined;
      this.queryParams.orderByColumn = undefined;
      this.queryParams.pageNum = 1;
      this.$refs.tables.clearSort();
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = this.getLowLineCase(column.prop);
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },

    reset() {
      this.form={
        id : undefined,
        applyIds : undefined,
        pass : undefined,
        notes : undefined,
      }
      this.resetForm("form");
    },
    cancel() {
      this.open = false;
      this.reset();
    },
    handlePass(row) {
      this.reset();
      if(row && row.id){
        this.form.id = row.id;
        this.form.applyIds = [row.id];
      }else{
        this.form.applyIds = this.ids;
      }
      this.open = true;
      this.title = "审核";
      this.form.score = row.score
    },
    /** 提交按钮 */
    submitForm() {

      this.$refs["form"].validate(valid => {
        if (valid) {
          this.request({
            url: '/points/poiApplyExamine/poiApplyExamine',
            method: 'post',
            data: this.form
          }).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
  }
};
</script>

